<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <img src="./img/键盘事件.png">
</body>
<script>
  /* 
  keypress不能识别功能建的ctrl,shift,alt,箭头
  三个建的执行顺序: keydown keypress keyup
  监听事件对象中的codekey属性可以得到相应的ASCII的值
    keyup和keydown不会区分字母的大小写，a和A得到的都是65
  */
  /* document.addEventListener("keyup", (e) => {
    console.log(e);
  });
  document.addEventListener("keydown", (e) => {
    console.log(e);
  });
  document.addEventListener("keypress", (e) => {
    console.log(e);
  }); */
</script>
<script>
  //禁止任何键盘敲击事件（防止F12和shift+ctrl+i调起开发者工具）
  window.onkeydown = window.onkeyup = window.onkeypress = function () {
    window.event.returnValue = false;
    return false;
  };
  
  // 当页面的宽度发生该改变时，关闭窗口
  let h = window.innerHeight;
  let w = window.innerWidth;
  window.addEventListener("resize", () => {
    if (h != window.innerHeight || w != window.innerWidth) {
      window.close();
      window.location = "about:blank";
    }
  });
</script>

</html>